﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// ManageExamineePage.xaml 的交互逻辑
        /// </summary>
        public partial class ManageTravelsPage : Page
        {
                private readonly GlobalManager gm = GlobalManager.Instance;

                public ManageTravelsPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        if (gm.Travel == null)
                        {
                                MessageBox.Show("请先登录系统");
                                NavigationService.Navigate(new Uri("StartPage.xaml", UriKind.Relative));
                        }
                        LayoutRoot.DataContext = gm;
                }

                private void CreateButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("CreateTravelPage.xaml", UriKind.Relative));
                }

                private void UpdateButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("UpdateTravelPage.xaml", UriKind.Relative));
                }

                private void DeleteButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (gm.Travel == null)
                        {
                                MessageBox.Show("请选定要删除的门类");
                                return;
                        }

                        if (
                                MessageBox.Show("确定要删除" + gm.Travel.StartTime + "出行的差旅及其信息吗？",
                                                "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                                gm.Travel.Delete();
                                gm.Travel = null;

                                NavigationService.Navigate(new Uri("ManageTravelsPage.xaml", UriKind.Relative));
                        }
                }

                private void SearchButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("SearchTravelPage.xaml", UriKind.Relative));
                }

                private void TravelsListBox_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
                {
                        if (gm.Travel == null)
                        {
                                MessageBox.Show("请选择要查看的门类");
                                return;
                        }

                        NavigationService.Navigate(new Uri("TravelInfoPage.xaml", UriKind.Relative));
                }

                
                
        }
}